/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.server.protocl  
 */
package com.apache.rpc.server.protocl;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.log4j.Logger;

import com.apache.api.api.SystemService;

/**
 * description:  webService通信接口实现
 * @author Hou Dayu 创建时间：2014-10-28  
 * @Copyright(c)2014:
 */
public class WebServiceProtocolService extends AbstractProtocolService {

	private Logger logger = Logger.getLogger(WebServiceProtocolService.class);

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.api.SystemService#doService(java.lang.String, com.apache.api.api.SystemService.ParamType)  
	 */
	public String doService(String params, ParamType type) {

		// TODO Auto-generated method stub
		return getWebservice(this.httpUrl, params, type);
	}

	private String getWebservice(String url, String params, ParamType type) {

		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(SystemService.class);
		String wsurl = url + "/services/SystemService?wsdl";
		factory.setAddress(wsurl);
		String result = "";
		try {
			SystemService hs = (SystemService) factory.create();
			result = hs.doService(params, type);
		} catch (Exception e) {
			logger.error(e);
		}
		return result;
	}

}
